
package edu.uoc.tdp.client.proves;

import edu.uoc.tdp.beans.conexio.ResponsableEvents;
import edu.uoc.tdp.beans.proves.EstatProva;
import edu.uoc.tdp.beans.proves.Prova;
import edu.uoc.tdp.common.EOlympicsUtils;
import edu.uoc.tdp.common.RemotProvesInterface;
import edu.uoc.tdp.common.TDSLanguageUtils;
import java.rmi.RemoteException;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumnModel;

/**
 *  Panell per mostra i tancar les inscripcions de l'olímpiada
 * @author Grup TDP 1X4J
 */
public class PanelControlInscripcions extends javax.swing.JFrame {
    private RemotProvesInterface remotProves;
    private ResponsableEvents usuari;
    private List<Prova> proves;
    private Prova provaSeleccionada;
    
    /**
     * Constructor per defecte
     */
    public PanelControlInscripcions() {
        initComponents();
        borrarDades();
        pintarEtiquetes();            
    }
    /**
     * Constructor amb un paràmetre
     * @param pProves 
     */
    public PanelControlInscripcions(List<Prova> pProves) {
        this();        
        this.proves=pProves;
        carregarProves();
    }
    /**
     * Constructor amb dos paràmetres,és el que es fa servir via remot
     * @param pUsuari
     * @param pRemotProves 
     */
    public PanelControlInscripcions(ResponsableEvents pUsuari,RemotProvesInterface pRemotProves){
        this();
        this.remotProves=pRemotProves;
        this.usuari=pUsuari;
        try {
            proves=remotProves.getProvesInscripcions();
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage(), "ERR", JOptionPane.ERROR_MESSAGE);                                
        } 
        carregarProves();
    }

    
    /**
     * Carrega les proves al panell
     */
    private void carregarProves(){
        
            try {                    
                jLabelData.setText(EOlympicsUtils.getStringDate(new java.util.Date()));             
                jTaulaInscripcio.setModel(carregarTaula(proves)); 
                if(proves.isEmpty()){
                    JOptionPane.showMessageDialog(null, TDSLanguageUtils.getMessage("proves.pantalla.inscrits.noelements.panelinscripcions"), TDSLanguageUtils.getMessage("proves.pantalla.manteniment.optionmessage.confirmacio"), JOptionPane.INFORMATION_MESSAGE);                                                                   
                }
                TableColumnModel modelColumna = jTaulaInscripcio.getColumnModel();         
                modelColumna.getColumn(0).setPreferredWidth(250);
                modelColumna.getColumn(3).setPreferredWidth(200);
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(null, ex.getMessage(), "ERR", JOptionPane.ERROR_MESSAGE);                                
            }
         
    }
    /**
     * Carrega les dades al model de la taula
     * @param proves            Dades
     * @return                  Model
     */
     private DefaultTableModel carregarTaula(List<Prova> proves){
        String [] columnes={"PROVA","Inscripció", "INSCRITS","ESTAT"};        
        Object[][] dades=new Object[proves.size()][4];                          
        Integer i=0;
        DefaultTableModel dadesTaula;
          for(Prova p:proves){
                dades[i][0]=p.getDescripcio();
                dades[i][1]=p.getNombrePlaces();
                dades[i][2]=p.getNombreInscrits();
                dades[i][3]=p.getEstat();
                i++;
        }        
        dadesTaula=new DefaultTableModel(dades,columnes)
                 {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false,false,false
            };

            @Override
            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
            
            @Override
            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        };
        
        
        
        return dadesTaula;        
    } 
     /**
      * Personalitza les etiquetes del pannell
      */
    private void pintarEtiquetes(){
        jBSortir.setToolTipText(TDSLanguageUtils.getMessage("proves.pantalla.inscrits.tooltip.jBSortir"));
        jBSortir.setText(TDSLanguageUtils.getMessage("proves.pantalla.buscador.settext.sortir"));
        
        jBTancarComp.setToolTipText(TDSLanguageUtils.getMessage("proves.pantalla.inscrits.tooltip.jBTancarComp"));
        jBTancarComp.setText(TDSLanguageUtils.getMessage("proves.pantalla.inscrits.settext.jBTancarComp"));
        jBCercarProves.setText(TDSLanguageUtils.getMessage("proves.pantalla.inscrits.settext.jBCercarProves"));
        jBCercarProves.setToolTipText(TDSLanguageUtils.getMessage("proves.pantalla.inscrits.tooltip.jBCercarProves"));
        this.setTitle(TDSLanguageUtils.getMessage("proves.pantalla.inscrits.settitol.panelinscripcions"));
        
        jLFiInscripcio.setText(TDSLanguageUtils.getMessage("proves.pantalla.tancar.settext.jLFiInscripcio"));
        jLFiRealitzacio.setText(TDSLanguageUtils.getMessage("proves.pantalla.tancar.settext.jLFiRealitzacio"));
        jLIniInscripcio.setText(TDSLanguageUtils.getMessage("proves.pantalla.tancar.settext.jLIniInscripcio"));
        jLIniRealitzacio.setText(TDSLanguageUtils.getMessage("proves.pantalla.tancar.settext.jLIniRealitzacio"));
        jLProva.setText(TDSLanguageUtils.getMessage("proves.pantalla.tancar.settext.jLProva"));
        jLRonda.setText(TDSLanguageUtils.getMessage("proves.pantalla.tancar.settext.jLRonda"));
        jLabelData1.setText(TDSLanguageUtils.getMessage("proves.pantalla.tancar.settext.jLabelData1"));
        
    }
    /**
     * Neteja de dades el pannell
     */
    private void borrarDades(){
        jTIdProva.setText("");
        jTDescripcio.setText("");
        jTFiInscripcio.setText("");
        jTFiRealitzacio.setText("");
        jTIniciInscripcio.setText("");
        jTIniciRealitzacio.setText("");
        jTRonda.setText("");
        jBTancarComp.setEnabled(false);
    }
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPbotons = new javax.swing.JPanel();
        jLabelData = new javax.swing.JLabel();
        jLabelData1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTaulaInscripcio = new javax.swing.JTable();
        jBSortir = new javax.swing.JButton();
        jBTancarComp = new javax.swing.JButton();
        jLIniInscripcio = new javax.swing.JLabel();
        jLFiInscripcio = new javax.swing.JLabel();
        jTDescripcio = new javax.swing.JLabel();
        jTIniciInscripcio = new javax.swing.JLabel();
        jTFiInscripcio = new javax.swing.JLabel();
        jTRonda = new javax.swing.JLabel();
        jLRonda = new javax.swing.JLabel();
        jLIniRealitzacio = new javax.swing.JLabel();
        jTIniciRealitzacio = new javax.swing.JLabel();
        jTFiRealitzacio = new javax.swing.JLabel();
        jLFiRealitzacio = new javax.swing.JLabel();
        jBCercarProves = new javax.swing.JButton();
        jLProva = new javax.swing.JLabel();
        jTIdProva = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });

        jLabelData.setFont(new java.awt.Font("Tahoma", 2, 12)); // NOI18N
        jLabelData.setForeground(javax.swing.UIManager.getDefaults().getColor("PropSheet.selectedSetBackground"));
        jLabelData.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabelData.setText("jLabel1");
        jLabelData.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

        jLabelData1.setFont(new java.awt.Font("Tahoma", 2, 12)); // NOI18N
        jLabelData1.setForeground(javax.swing.UIManager.getDefaults().getColor("PropSheet.selectedSetBackground"));
        jLabelData1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabelData1.setText("Data Actual:");
        jLabelData1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

        javax.swing.GroupLayout jPbotonsLayout = new javax.swing.GroupLayout(jPbotons);
        jPbotons.setLayout(jPbotonsLayout);
        jPbotonsLayout.setHorizontalGroup(
            jPbotonsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPbotonsLayout.createSequentialGroup()
                .addContainerGap(56, Short.MAX_VALUE)
                .addComponent(jLabelData1, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabelData, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jPbotonsLayout.setVerticalGroup(
            jPbotonsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPbotonsLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPbotonsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelData, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelData1, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(23, Short.MAX_VALUE))
        );

        jTaulaInscripcio.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Prova", "Title 2", "Title 3", "Title 4"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTaulaInscripcio.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS);
        jTaulaInscripcio.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jTaulaInscripcioMousePressed(evt);
            }
        });
        jScrollPane1.setViewportView(jTaulaInscripcio);

        jBSortir.setFont(new java.awt.Font("Tahoma", 0, 10));
        jBSortir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/BotoSortir.png"))); // NOI18N
        jBSortir.setText("Sortir");
        jBSortir.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jBSortir.setPreferredSize(new java.awt.Dimension(65, 60));
        jBSortir.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jBSortir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBSortirActionPerformed(evt);
            }
        });

        jBTancarComp.setText("Tancar Inscripcions");
        jBTancarComp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBTancarCompActionPerformed(evt);
            }
        });

        jLIniInscripcio.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLIniInscripcio.setText("Inici Inscricpció:");

        jLFiInscripcio.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLFiInscripcio.setText("FinalInscripció:");

        jTDescripcio.setForeground(java.awt.Color.blue);

        jTIniciInscripcio.setForeground(java.awt.Color.blue);

        jTFiInscripcio.setForeground(java.awt.Color.blue);
        jTFiInscripcio.setText(".");

        jTRonda.setForeground(java.awt.Color.blue);
        jTRonda.setText(".");

        jLRonda.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLRonda.setText("Ronda:");

        jLIniRealitzacio.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLIniRealitzacio.setText("Inici Realització");

        jTIniciRealitzacio.setForeground(java.awt.Color.blue);
        jTIniciRealitzacio.setText(".");

        jTFiRealitzacio.setForeground(java.awt.Color.blue);
        jTFiRealitzacio.setText(".");

        jLFiRealitzacio.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLFiRealitzacio.setText("Final Realització");

        jBCercarProves.setText("Cercar Proves");
        jBCercarProves.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBCercarProvesActionPerformed(evt);
            }
        });

        jLProva.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLProva.setText("Inici Inscricpció:");

        jTIdProva.setForeground(java.awt.Color.blue);
        jTIdProva.setText(".");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(jBSortir, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 122, Short.MAX_VALUE)
                        .addComponent(jPbotons, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(45, 45, 45)
                        .addComponent(jTDescripcio, javax.swing.GroupLayout.PREFERRED_SIZE, 447, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(jLFiInscripcio, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jLIniInscripcio, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jTFiInscripcio, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jTIniciInscripcio, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(jLFiRealitzacio, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jLIniRealitzacio, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(68, 68, 68)
                                .addComponent(jLProva)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTIdProva, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLRonda, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTRonda, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(jTFiRealitzacio, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jTIniciRealitzacio, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jBCercarProves, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 156, Short.MAX_VALUE)
                .addComponent(jBTancarComp, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(30, 30, 30))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 490, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jBSortir, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jPbotons, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jTDescripcio)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jTRonda, javax.swing.GroupLayout.DEFAULT_SIZE, 14, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLRonda)
                        .addComponent(jLProva))
                    .addComponent(jTIdProva, javax.swing.GroupLayout.DEFAULT_SIZE, 14, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLIniInscripcio)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLFiInscripcio))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jTIniciRealitzacio)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTFiRealitzacio))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jTIniciInscripcio, javax.swing.GroupLayout.DEFAULT_SIZE, 14, Short.MAX_VALUE)
                            .addComponent(jLIniRealitzacio))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLFiRealitzacio)
                            .addComponent(jTFiInscripcio))))
                .addGap(30, 30, 30)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBTancarComp)
                    .addComponent(jBCercarProves))
                .addContainerGap(26, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    /**
     * Acció de sortir del pannell, passa al clicar el botó tancar
     * @param evt           disparador
     */
    private void jBSortirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBSortirActionPerformed
        this.dispose();
    }//GEN-LAST:event_jBSortirActionPerformed
    
    /**
     * Acció de sortir del pannell, passa al tancar la finestra
     * @param evt 
     */
    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        this.dispose();
    }//GEN-LAST:event_formWindowClosed
    /**
     * Acció de tancar una inscripció. 
     * Tanca l'inscripció i actualitza la participacio
     * @param evt           disparador
     */
    private void jBTancarCompActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBTancarCompActionPerformed
        
        String msg="";
        EstatProva tempEstat=null;
        if(provaSeleccionada.getNombreInscrits()< 3 ){
            msg= TDSLanguageUtils.getMessage("proves.pantalla.inscrits.confirmacio.deserta")+" "+EstatProva.DESERTA.getEstat() ;
            tempEstat=EstatProva.DESERTA;
        }else if (provaSeleccionada.getNombreInscrits()< 11){
            msg= TDSLanguageUtils.getMessage("proves.pantalla.inscrits.confirmacio.final")+" "+EstatProva.COMPETICIOFINAL.getEstat() ;
            tempEstat=EstatProva.COMPETICIOFINAL;              
        }else{
            msg= TDSLanguageUtils.getMessage("proves.pantalla.inscrits.confirmacio.competicioprevia") + " " + EstatProva.COMPETICIOPREVIA.getEstat();            
            tempEstat=EstatProva.COMPETICIOPREVIA;
        }                             
        if( JOptionPane.showConfirmDialog                           
                        (null, msg, 
                        TDSLanguageUtils.getMessage("proves.pantalla.inscrits.confirmacio.tancarinscripcions"), JOptionPane.OK_CANCEL_OPTION)==0){                   
                provaSeleccionada.setEstat(tempEstat);
                try {
                    provaSeleccionada.setUsuariModificacio(usuari);
                    remotProves.tancarInscripcio(provaSeleccionada);            
                    JOptionPane.showMessageDialog(null, TDSLanguageUtils.getMessage("proves.pantalla.inscrits.confirmacio.panelinscripcions"), TDSLanguageUtils.getMessage("proves.pantalla.manteniment.optionmessage.confirmacio"), JOptionPane.INFORMATION_MESSAGE);                                                                   
                    borrarDades();
                    proves=remotProves.getProvesInscripcions();
                    carregarProves();            
                }catch (RemoteException re){
                        JOptionPane.showMessageDialog(null,TDSLanguageUtils.getMessage("ERR_REMOT") , "ERR", JOptionPane.ERROR_MESSAGE);                                
                }catch (Exception e) {
                     JOptionPane.showMessageDialog(null, e.getMessage(), "ERR", JOptionPane.ERROR_MESSAGE);                                
                }
        
        }
        
    }//GEN-LAST:event_jBTancarCompActionPerformed
/**
     *  Acció de cercar proves en periode d'isncripció exhaurit
     * @param evt           Disparador
     */
    private void jBCercarProvesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBCercarProvesActionPerformed
        try{
            proves=remotProves.getProvesInscripcions();       
            borrarDades();
            carregarProves();            
        }catch (RemoteException re){
            JOptionPane.showMessageDialog(null,TDSLanguageUtils.getMessage("ERR_REMOT") , "ERR", JOptionPane.ERROR_MESSAGE);                                
        }catch (Exception e){
            if (e.getMessage()==null){
                JOptionPane.showMessageDialog(null,TDSLanguageUtils.getMessage("ERR_CONEXIO_DESC") , "ERR", JOptionPane.ERROR_MESSAGE);                                
            }else{
                JOptionPane.showMessageDialog(null, e.getMessage(), "ERR", JOptionPane.ERROR_MESSAGE);                                
            }
            
        }        
    }//GEN-LAST:event_jBCercarProvesActionPerformed
    /**
     * Acció de seleccionar una prova de la taula
     * @param evt           Disparador
     */
    private void jTaulaInscripcioMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTaulaInscripcioMousePressed
        if(jTaulaInscripcio.getSelectedRow()>=0){
            provaSeleccionada=proves.get(jTaulaInscripcio.getSelectedRow());
            jTIdProva.setText(provaSeleccionada.getIdProva().toString());
            jTIniciInscripcio.setText(EOlympicsUtils.getStringDate(provaSeleccionada.getDataIniInscripcio()));
            jTFiInscripcio.setText(EOlympicsUtils.getStringDate(provaSeleccionada.getDataFiInscripcio()));

            if(provaSeleccionada.getRondaEliminatoria()!=null){
                jTRonda.setText("ELIMINATORIA");
                jTIniciRealitzacio.setText(EOlympicsUtils.getStringDate(provaSeleccionada.getRondaEliminatoria().getDataIniRealitzacio()));
                jTFiRealitzacio.setText(EOlympicsUtils.getStringDate(provaSeleccionada.getRondaEliminatoria().getDataFiRealitzacio()));
            }else{
                jTRonda.setText("FINAL");
                jTIniciRealitzacio.setText(EOlympicsUtils.getStringDate(provaSeleccionada.getRondaFinal().getDataIniRealitzacio()));
                jTFiRealitzacio.setText(EOlympicsUtils.getStringDate(provaSeleccionada.getRondaFinal().getDataFiRealitzacio()));
            }
            jBTancarComp.setEnabled(true);
       }
    }//GEN-LAST:event_jTaulaInscripcioMousePressed

    
    
 
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBCercarProves;
    private javax.swing.JButton jBSortir;
    private javax.swing.JButton jBTancarComp;
    private javax.swing.JLabel jLFiInscripcio;
    private javax.swing.JLabel jLFiRealitzacio;
    private javax.swing.JLabel jLIniInscripcio;
    private javax.swing.JLabel jLIniRealitzacio;
    private javax.swing.JLabel jLProva;
    private javax.swing.JLabel jLRonda;
    private javax.swing.JLabel jLabelData;
    private javax.swing.JLabel jLabelData1;
    private javax.swing.JPanel jPbotons;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel jTDescripcio;
    private javax.swing.JLabel jTFiInscripcio;
    private javax.swing.JLabel jTFiRealitzacio;
    private javax.swing.JLabel jTIdProva;
    private javax.swing.JLabel jTIniciInscripcio;
    private javax.swing.JLabel jTIniciRealitzacio;
    private javax.swing.JLabel jTRonda;
    private javax.swing.JTable jTaulaInscripcio;
    // End of variables declaration//GEN-END:variables
}
